<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="消防日期" prop="fireDate">
        <el-input
          v-model="queryParams.fireDate"
          placeholder="请输入消防日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警位置" prop="alarmLocation">
        <el-input
          v-model="queryParams.alarmLocation"
          placeholder="请输入报警位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警级别" prop="alarmLevel">
        <el-input
          v-model="queryParams.alarmLevel"
          placeholder="请输入报警级别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前状态" prop="currentStatus">
        <el-input
          v-model="queryParams.currentStatus"
          placeholder="请输入当前状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="位置ID" prop="locationId">
        <el-input
          v-model="queryParams.locationId"
          placeholder="请输入位置ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="摄像头ID" prop="cameraId">
        <el-input
          v-model="queryParams.cameraId"
          placeholder="请输入摄像头ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['fire_alarm:fire_alarm:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['fire_alarm:fire_alarm:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['fire_alarm:fire_alarm:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fire_alarm:fire_alarm:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fire_alarmList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键，唯一标识" align="center" prop="id" />
      <el-table-column label="消防日期" align="center" prop="fireDate" />
      <el-table-column label="报警位置" align="center" prop="alarmLocation" />
      <el-table-column label="报警车位号" align="center" prop="alarmParkingSpot" />
      <el-table-column label="报警级别" align="center" prop="alarmLevel" />
      <el-table-column label="当前温度" align="center" prop="currentTemperature" />
      <el-table-column label="消防处理人" align="center" prop="handlerName" />
      <el-table-column label="消防处理人联系方式" align="center" prop="handlerContact" />
      <el-table-column label="物业姓名" align="center" prop="propertyName" />
      <el-table-column label="物业联系方式" align="center" prop="propertyContact" />
      <el-table-column label="维护人姓名" align="center" prop="maintainerName" />
      <el-table-column label="维护人联系方式" align="center" prop="maintainerContact" />
      <el-table-column label="当前状态" align="center" prop="currentStatus" />
      <el-table-column label="位置ID" align="center" prop="locationId" />
      <el-table-column label="经纬度信息" align="center" prop="gpsCoordinates" />
      <el-table-column label="摄像头ID" align="center" prop="cameraId" />
      <el-table-column label="后续处理情况" align="center" prop="followUp" />
      <el-table-column label="温度上升曲线" align="center" prop="temperatureRiseCurve" />
      <el-table-column label="预留字段1" align="center" prop="reservedField1" />
      <el-table-column label="预留字段2" align="center" prop="reservedField2" />
      <el-table-column label="预留字段3" align="center" prop="reservedField3" />
      <el-table-column label="记录创建时间" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="记录更新时间" align="center" prop="updatedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fire_alarm:fire_alarm:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fire_alarm:fire_alarm:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改消防对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="消防日期" prop="fireDate">
          <el-input v-model="form.fireDate" placeholder="请输入消防日期" />
        </el-form-item>
        <el-form-item label="报警位置" prop="alarmLocation">
          <el-input v-model="form.alarmLocation" placeholder="请输入报警位置" />
        </el-form-item>
        <el-form-item label="报警车位号" prop="alarmParkingSpot">
          <el-input v-model="form.alarmParkingSpot" placeholder="请输入报警车位号" />
        </el-form-item>
        <el-form-item label="报警级别" prop="alarmLevel">
          <el-input v-model="form.alarmLevel" placeholder="请输入报警级别" />
        </el-form-item>
        <el-form-item label="当前温度" prop="currentTemperature">
          <el-input v-model="form.currentTemperature" placeholder="请输入当前温度" />
        </el-form-item>
        <el-form-item label="消防处理人" prop="handlerName">
          <el-input v-model="form.handlerName" placeholder="请输入消防处理人" />
        </el-form-item>
        <el-form-item label="消防处理人联系方式" prop="handlerContact">
          <el-input v-model="form.handlerContact" placeholder="请输入消防处理人联系方式" />
        </el-form-item>
        <el-form-item label="物业姓名" prop="propertyName">
          <el-input v-model="form.propertyName" placeholder="请输入物业姓名" />
        </el-form-item>
        <el-form-item label="物业联系方式" prop="propertyContact">
          <el-input v-model="form.propertyContact" placeholder="请输入物业联系方式" />
        </el-form-item>
        <el-form-item label="维护人姓名" prop="maintainerName">
          <el-input v-model="form.maintainerName" placeholder="请输入维护人姓名" />
        </el-form-item>
        <el-form-item label="维护人联系方式" prop="maintainerContact">
          <el-input v-model="form.maintainerContact" placeholder="请输入维护人联系方式" />
        </el-form-item>
        <el-form-item label="当前状态" prop="currentStatus">
          <el-input v-model="form.currentStatus" placeholder="请输入当前状态" />
        </el-form-item>
        <el-form-item label="位置ID" prop="locationId">
          <el-input v-model="form.locationId" placeholder="请输入位置ID" />
        </el-form-item>
        <el-form-item label="经纬度信息" prop="gpsCoordinates">
          <el-input v-model="form.gpsCoordinates" placeholder="请输入经纬度信息" />
        </el-form-item>
        <el-form-item label="摄像头ID" prop="cameraId">
          <el-input v-model="form.cameraId" placeholder="请输入摄像头ID" />
        </el-form-item>
        <el-form-item label="后续处理情况" prop="followUp">
          <el-input v-model="form.followUp" placeholder="请输入后续处理情况" />
        </el-form-item>
        <el-form-item label="温度上升曲线" prop="temperatureRiseCurve">
          <el-input v-model="form.temperatureRiseCurve" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reservedField1">
          <el-input v-model="form.reservedField1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reservedField2">
          <el-input v-model="form.reservedField2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reservedField3">
          <el-input v-model="form.reservedField3" placeholder="请输入预留字段3" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFire_alarm, getFire_alarm, delFire_alarm, addFire_alarm, updateFire_alarm } from "@/api/fire_alarm/fire_alarm";

export default {
  name: "Fire_alarm",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 消防表格数据
      fire_alarmList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fireDate: null,
        alarmLocation: null,
        alarmLevel: null,
        currentStatus: null,
        locationId: null,
        cameraId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createdAt: [
          { required: true, message: "记录创建时间不能为空", trigger: "blur" }
        ],
        updatedAt: [
          { required: true, message: "记录更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询消防列表 */
    getList() {
      this.loading = true;
      listFire_alarm(this.queryParams).then(response => {
        this.fire_alarmList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fireDate: null,
        alarmLocation: null,
        alarmParkingSpot: null,
        alarmLevel: null,
        currentTemperature: null,
        handlerName: null,
        handlerContact: null,
        propertyName: null,
        propertyContact: null,
        maintainerName: null,
        maintainerContact: null,
        currentStatus: null,
        locationId: null,
        gpsCoordinates: null,
        cameraId: null,
        followUp: null,
        temperatureRiseCurve: null,
        reservedField1: null,
        reservedField2: null,
        reservedField3: null,
        createdAt: null,
        updatedAt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加消防";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFire_alarm(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改消防";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFire_alarm(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFire_alarm(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除消防编号为"' + ids + '"的数据项？').then(function() {
        return delFire_alarm(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fire_alarm/fire_alarm/export', {
        ...this.queryParams
      }, `fire_alarm_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
